import Vue from 'vue'
import Vuex from 'vuex'
import collection from './modules/collection.js'
import workflow from './modules/workflow.js'
import wschat from './modules/wschat.js'

Vue.use(Vuex)

let state = { //要设置的全局访问的state对象
	defsyslogn: {
		userId: '',
		applyId: '',
		token: '',
		account: '',
		accountHeadurl: '',
		accountNick: '',
		password: ''
	},
	friend: {
		friendId: '',
		friendHeadurl: '',
		friendNnick: ''
	}
};
let getters = { //实时监听state值的变化(最新状态)
	islogin(state) { //承载变化的showFooter的值
		return state.defsyslogn.token
	},
};
let mutations = {
	login(state, provider) { //自定义改变state初始值的方法，这里面的参数除了state之外还可以再传额外的参数(变量或对象);
		state.defsyslogn.token = provider.token;
		state.defsyslogn.account = provider.account;
	},
	logout(state) {
		state.defsyslogn.token = '';
		state.defsyslogn.account = '';
	},
	setSysLogn(state, item) {
		state.defsyslogn = item;
	},
	unfriend(state){
		state.friend.friendId = '';
		state.friend.friendHeadurl = '';
		state.friend.friendNnick = '';
	},
	setFriend(state,item){
		state.friend.friendId = item.friendId;
		state.friend.friendHeadurl = item.friendHeadurl;
		state.friend.friendNnick = item.friendNnick;
	}
};
let actions = {
	// setSysLognb(context){
	// 	context.commit(setSysLogn);
	// }
};
//存储数据和管理数据方法的仓库，实现方式是将数据和方法已对象形式传入其实例中。要注意一个应用或是项目中只能存在一个Store实例！！
let store = new Vuex.Store({
	state,
	getters,
	mutations,
	actions,
	modules: {
		collection,
		workflow,
		wschat
	}
})

export default store
